import React, { Component } from 'react';
import { Form, Input } from 'antd';
import PropTypes from 'prop-types';

/**
 * 添加，修改表单
 */
class AddUpdateForm extends Component {
    // static 给类添加
    // 没有static，给对象实例添加
    static propTypes = {
        setForm: PropTypes.func.isRequired
    }
    
    componentWillMount() {
        // 尽早把form给过去
        this.props.setForm(this.props.form);
    }

    handleSubmit = (e) => {
        
    }

    render() {
        const { getFieldDecorator } = this.props.form;
        return (
            <div>
                <Form onSubmit={this.handleSubmit}>
                    <Form.Item>
                        {
                            // getFieldDecorator()()
                            // getFieldDecorator是一个高阶函数
                            getFieldDecorator('categoryname', {
                                initialValue: this.props.name || '', // 定义初始值
                                // 配置对象
                                rules: [
                                    { required: true, whitespace: true, message: '请输入商品分类名称', },
                                ],
                            })(
                                <Input
                                    placeholder="商品分类名称"
                                />
                            )
                        }
                    </Form.Item>
                </Form>
            </div>
        )
    }
}

export default Form.create()(AddUpdateForm);
